﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace RastinArgham.CRM.Business
{
    [MetadataType(typeof(ContactMetaData))]
    [DisplayName("مشترک")]
    [ScaffoldTable(true)]
    [ReadOnly(true)]
    public partial class Contact
    {
        public String CityName {
            get { return this.City.CityName; }
        }

        public String ContactTypeDescription
        {
            get { return this.ContactType.ContactTypeDescription; }
        }

        public String EditLink
        {
            get
            {
                if (this.ContactTypeId == (int)ContactTypes.Company)
                    return "company_contact.aspx?id=" + this.ContactId.ToString();
                else
                    return "personal_contact.aspx?id=" + this.ContactId.ToString();
            }
        }

        public String ServicesLink
        {
            get
            {
                return "order_services.aspx?id=" + this.ContactId.ToString();
            }
        }

        public String ProductsLink
        {
            get
            {
                return "order_product.aspx?id=" + this.ContactId.ToString();
            }
        }

        public String GetUsername()
        {
            Order modemOrder = this.Orders.Where(o => o.ProductId != null && o.WorkflowStateId != 50).FirstOrDefault();
            if (modemOrder != null)
                return modemOrder.SubID;
            else
                return String.Empty;
        }

        public Order GetModemOrder()
        {
            Order modemOrder = this.Orders.Where(o => o.ProductId != null && o.WorkflowStateId != 50).FirstOrDefault();
            return modemOrder;
        }

        public List<Order> ServiceOrders
        {
            get
            {
                var result = this.Orders.Where(o => o.ServiceId.HasValue);
                return result.ToList();
            }
        }
    }

    public class ContactMetaData
    {
        [Display(Name="نحوه معرفی")]
        public object LeadSource { get; set; }

        [Display(Name="شهر")]
        public object City { get; set; }

        [Display(Name="نوع شخص")]
        public object ContactType { get; set; }

        [ScaffoldColumn(false)]
        public object Orders { get; set; }

        [ScaffoldColumn(false)]
        public object CompanyContacts { get; set; }

        [ScaffoldColumn(false)]
        public object PersonalContacts { get; set; }

        [ScaffoldColumn(false)]
        public object MobinReference { get; set; }

        [ScaffoldColumn(false)]
        public object Marketer { get; set; }

        [ScaffoldColumn(false)]
        public object FullContactTitle { get; set; }

        [ScaffoldColumn(false)]
        public object Fax { get; set; }

        [ScaffoldColumn(false)]
        public object Website { get; set; }

        [ScaffoldColumn(false)]
        public object ZipCode { get; set; }

        [ScaffoldColumn(false)]
        public object Address { get; set; }

        [UIHint("link:/order_services.aspx?id=")]
        [Display(Name="کد شخص")]
        public object ContactId { get; set; }

        [Display(Name="عنوان شخص")]
        public object ContactTitle { get; set; }

        [Display(Name = "تلفن")]
        public object Phone { get; set; }

        [Display(Name="تلفن همراه")]
        public object MobilePhone { get; set; }

        [Display(Name="تاریخ ایجاد")]
        public object CreateDate { get; set; }

        [ScaffoldColumn(false)]
        public object LastUpdate { get; set; }
    }
}
